package com.libmessagecenter

import android.content.Context
import android.content.Intent
import android.util.Log
import com.heytap.msp.push.HeytapPushManager
import com.heytap.msp.push.callback.ICallBackResultService
import com.heytap.msp.push.service.DataMessageCallbackService
import com.libbase.utils.JsonUtils
import com.libmessagecenter.models.Message

class OppoPushMessageService : DataMessageCallbackService() {
    companion object {
        const val TAG = "OppoPushMessageService"

        val pushSDK = object : PushSDKInterface {
            override fun register(context: Context, appId: String?, appKey: String?) {
                HeytapPushManager.init(context, true)
                HeytapPushManager.register(context, appId, appKey, object : ICallBackResultService {
                    override fun onRegister(responseCode: Int, s: String?) {
                        if (responseCode == 0) {
                            Log.i(TAG, "注册成功，registerId: $s")

                            s?.let {
                                LibMessageCenter.instance.register(it)
                            }
                        } else {
                            Log.e(TAG, "注册失败，code: ${responseCode}, msg: $s")
                        }
                    }

                    override fun onUnRegister(responseCode: Int) {
                        Log.i(TAG, "onUnRegister, code: $responseCode")
                    }

                    override fun onSetPushTime(responseCode: Int, pushTime: String?) {
                        Log.i(
                            TAG, "onSetPushTime, code: $responseCode, pushTime: $pushTime"
                        )
                    }

                    override fun onGetPushStatus(responseCode: Int, status: Int) {
                        Log.i(TAG, "onGetPushStatus, code: $responseCode, status: $status")
                    }

                    override fun onGetNotificationStatus(responseCode: Int, status: Int) {
                        Log.i(
                            TAG, "onGetNotificationStatus, code: $responseCode, status: $status"
                        )
                    }

                    override fun onError(code: Int, msg: String?) {
                        Log.i(TAG, "onError, code: $code, msg: $msg")
                    }
                })
            }
        }
    }
}